package cn.piesat.scanning.business.xz.service.snwimpl;

import cn.piesat.scanning.business.xz.service.BuildAlgorithmTaskService;
import cn.piesat.scanning.business.xz.single.AlgorithmTaskPathParam;
import cn.piesat.scanning.business.xz.single.AlgorithmTaskRuleParam;
import cn.piesat.scanning.dto.HtScanningMetadataDTO;
import cn.piesat.scanning.service.HtScanningMetadataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author Ming
 * @version 1.0
 * @description: TODO
 * @date 2023/12/18 13:48
 */
@Service
public class Build03_ZHFJServiceImpl implements BuildAlgorithmTaskService {
    @Autowired
    private HtScanningMetadataService htScanningMetadataService;
    @Override
    public Map<String, Object> initAlgorithmParams(String adsType, String primaryFile, String filePath, AlgorithmTaskRuleParam taskRuleParam, AlgorithmTaskPathParam taskPathParam,
                                                   Map<String, Integer> indexParams, String fileDate, String scanningPath,HtScanningMetadataDTO htScanningMetadataDTO) {
        Map<String, Object> algorithmParams = new HashMap<>();
        //SNW_SDFC_540000_L2_FY3D_MWRI_010KM_GLL_POAD_20230730000000_20231130235959.TIFF
        String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
        String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
        Map<String, Object> params = new HashMap<>();
        String[] s = fileName.split("_");
        String satellite = s[4].replace("-", "");
        String region = s[2].replace("-", "");
        String DATE = s[9].replace("-", "");

        LinkedList<HtScanningMetadataDTO> htScanningMetadataDTOS = htScanningMetadataService.findMetaDataDto(DATE, "L2", satellite,
                "SDFC", "540000", "TIFF");

        if (null == htScanningMetadataDTOS) {
            algorithmParams.put("parameter01", null);
        } else {
            List<String> fileList = new ArrayList<>();
            htScanningMetadataDTOS.forEach(x -> {
                fileList.add(taskPathParam.getParameter02() + x.getFilePath());
            });
            params.put("inputdir", fileList);
            params.put("auxpath", taskPathParam.getParameter03());
            params.put("sysname", taskPathParam.getParameter04());
            algorithmParams.put("parameter00", adsType);
            algorithmParams.put("parameter01", params);
        }
        return algorithmParams;
    }
}
